package decorator.pattern.demo;

/**
 * Created by DELL
 * Date: 2019/9/28.
 * Time: 14:56
 */
abstract class Component{
    public abstract void doJob();
}

class ConcreteComponent extends Component{

    @Override
    public void doJob() {
        System.out.println("I am fron Concrete Component-I am closed for modifiacation.");
    }
}

abstract class AbstractDecorator extends Component{
    protected Component com;
    public void setTheComponent(Component c){
        com = c;
    }
    @Override
    public void doJob() {
        com.doJob();
    }
}

//创建装饰器1
class ConcreteDecroatorEX_1 extends AbstractDecorator{
    @Override
    public void doJob() {
        super.doJob();
        //add additional thing if necessary
        System.out.println("I am explicaitly from Ex_1");
    }
}

//创建装饰器2
class ConcreteDecroatorEX_2 extends AbstractDecorator{
    @Override
    public void doJob() {
        super.doJob();
        System.out.println("***START Ex-2***");
        System.out.println();
        //add additional thing if necessary
        System.out.println("Explicitly From DecoratorEx_2");
        System.out.println("***END . Ex-2***");
    }
}


public class DecoratorPatternEX {
    public static void main(String[] args) {
        System.out.println("Hello Decorator Start");
        ConcreteComponent cc = new ConcreteComponent();
        ConcreteDecroatorEX_1 cd_1 = new ConcreteDecroatorEX_1();
        ConcreteDecroatorEX_2 cd_2 = new ConcreteDecroatorEX_2();
        //Decorating ConcreteComponent Object //cc with ConcreteDecoratorEx_1
        cd_1.setTheComponent(cc);
        cd_1.doJob();

        //Decorating ConcreteComponent Object //cc with ConcreteDecoratorEx_1
        cd_2.setTheComponent(cc);
        cd_2.doJob();
    }
}
